package 力扣._20_有效括号;

import java.util.Stack;

public class Solution {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(' || c == '{' || c == '[')
                stack.push(c);
            else {
                if(stack.empty())
                    return false;
                Character pop = stack.pop();
                if (!((pop == '(' && c == ')') ||(pop == '[' && c == ']') ||(pop == '{' && c == '}')))
                    return false;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        String s = ")()[]{}";
        boolean valid = new Solution().isValid(s);
        System.out.println(valid);
    }
}
